package nc.ui.arap.billquery;

import nc.ui.querytemplate.meta.FilterMeta;
import nc.ui.querytemplate.meta.IFilterMeta;
import nc.ui.querytemplate.operator.AbstractOperator;
import nc.ui.querytemplate.operator.IOperatorConstants;
import nc.ui.querytemplate.value.IFieldValue;

public class InOperator extends AbstractOperator {

	private static final long serialVersionUID = 79126814953707618L;

//	private static final InOperator INSTANCE = new InOperator();
//
//	public static InOperator getInstance() {
//		return INSTANCE;
//	}

	@Override
	public int getParameterNumber() {
		return -1;
	}

	@Override
	public String getOperatorCode() {
		return getMultiValueOperator();
	}

	@Override
	public String getSQLString(FilterMeta meta, IFieldValue value) {
		if (value == null || value.getFieldValues() == null || value.getFieldValues().size() == 0)
			return null;

		String valueString = value.getFieldValues().get(0).getSqlString();
		return meta.getSQLFieldCode() + " " + getMultiValueOperator() + " " + valueString;
	}

	public String getMultiValueOperator() {
		return IOperatorConstants.IN;
	}

	@Override
	public String toString() {
		return "in";
	}

	public String getDescription(IFilterMeta meta, IFieldValue value) {
		if (value == null || value.getFieldValues() == null || value.getFieldValues().size() == 0) {
			return meta.getFieldName();
		}
		String showString = value.getFieldValues().get(0).getShowString();
		return meta.getFieldName() + " " + toString() + " " + showString;

	}
}
